<?php
class DateWidget extends CInputWidget
{
    public $parseFormat = 'MMM/dd/yyyy';
    public $displayFormat = 'M/d/Y';
    public $displayJSFormat = 'mm/dd/yy';
    
    public function run()
    {
        if (empty($this->value) == false) {
            if (strpos($this->value, '/'))
                $timestamp = CDateTimeParser::parse($this->value, $this->parseFormat);
            else
                $timestamp = strtotime($this->value);
            if ($timestamp !== false)
                $this->value = Yii::app()->getDateFormatter()->format($this->displayFormat, $timestamp);
        }
        $this->widget('zii.widgets.jui.CJuiDatePicker', array(
            'name'=>$this->name,
            'value'=>$this->value,
            'options'=>array(
                'dateFormat'=>$this->displayJSFormat,
            ),
            'htmlOptions'=>$this->htmlOptions,
        ));
    }
}
